/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package modelo;

import controlador.ITareaController;
import java.util.*;
import modelo.persistencia.ITareaDAO;
import modelo.persistencia.TareaDAO;
/**
 *
 * @author LEONIC
 */
public class TareaModel implements ITareaModel{

    private ITareaController controller;

    public ITareaController getController() {
        return controller;
    }

    public void setController(ITareaController controller) {
        this.controller = controller;
    }

    public void nuevoTarea(ITarea tarea) {
        ITareaDAO dao = obtenerImplementacionTareaDAO();
        dao.create(tarea);
        fireModelChanged();
    }

    public void eliminarTarea(ITarea tarea) {
        ITareaDAO dao = obtenerImplementacionTareaDAO();
        dao.delete(tarea);
        fireModelChanged();
    }

    public ITarea obtenerTarea(String tarea) {
        ITareaDAO dao = obtenerImplementacionTareaDAO();
        return dao.read(tarea);
    }

    public void actualizarTarea(ITarea tarea) {
        ITareaDAO dao = obtenerImplementacionTareaDAO();
        dao.update(tarea);
        fireModelChanged();

    }

    public List<ITarea> obtenerTarea() {
        ITareaDAO dao = obtenerImplementacionTareaDAO();
        return dao.list();
    }

    private ITareaDAO obtenerImplementacionTareaDAO() {
        //return new ContactoDAOFile();
        return new TareaDAO();
    }

    protected void fireModelChanged() {
        getController().fireDataModelChanged();
    }

}
